package top.drinyeit.nongmao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

import top.drinyeit.nongmao.R;
import top.drinyeit.nongmao.model.RechargeBean;

/**
 * Created by Administrator on 2017/12/8.
 */

public class MineChongZhiGridAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater mInflater;
    private ArrayList<RechargeBean> rechargeBeanArrayList;

    public MineChongZhiGridAdapter(Context context, ArrayList<RechargeBean> rechargeBeanArrayList) {
        this.context = context;
        this.rechargeBeanArrayList = rechargeBeanArrayList;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return rechargeBeanArrayList == null ? 0 : rechargeBeanArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder0 viewHolder0 = null;
        if (convertView == null) {
            viewHolder0 = new ViewHolder0();
            convertView = mInflater.inflate(R.layout.item_chongzhi, null);
            viewHolder0.tv_chongzhi_amount = convertView.findViewById(R.id.tv_chongzhi_amount);
            viewHolder0.tv_chongzhi_other = convertView.findViewById(R.id.tv_chongzhi_other);
            viewHolder0.iv_chongzhi_checked = convertView.findViewById(R.id.iv_chongzhi_checked);
            viewHolder0.rl_item_chongzhi_root = convertView.findViewById(R.id.rl_item_chongzhi_root);
            convertView.setTag(viewHolder0);
        } else {
            viewHolder0 = (ViewHolder0) convertView.getTag();
        }
        RechargeBean rechargeBean = rechargeBeanArrayList.get(position);
        if (rechargeBean.getChecked()) {
            viewHolder0.rl_item_chongzhi_root.setBackgroundDrawable(context.getDrawable(R.drawable.item_chongzhi_checked));
            viewHolder0.tv_chongzhi_amount.setTextColor(context.getResources().getColor(R.color.orange_147));
            viewHolder0.tv_chongzhi_other.setTextColor(context.getResources().getColor(R.color.orange_147));
            viewHolder0.iv_chongzhi_checked.setVisibility(View.VISIBLE);
        } else {
            viewHolder0.rl_item_chongzhi_root.setBackgroundDrawable(context.getDrawable(R.drawable.item_chongzhi_unchecked));
            viewHolder0.tv_chongzhi_amount.setTextColor(context.getResources().getColor(R.color.gray_189));
            viewHolder0.tv_chongzhi_other.setTextColor(context.getResources().getColor(R.color.gray_189));
            viewHolder0.iv_chongzhi_checked.setVisibility(View.INVISIBLE);
        }
        viewHolder0.tv_chongzhi_amount.setText("￥" + rechargeBean.getPrice());
        viewHolder0.tv_chongzhi_other.setText("￥" + rechargeBean.getOther());
        return convertView;
    }


    private class ViewHolder0 {
        TextView tv_chongzhi_amount;

        TextView tv_chongzhi_other;

        ImageView iv_chongzhi_checked;

        LinearLayout rl_item_chongzhi_root;
    }

}
